package com.itheima.多线程.练习;

/*卖票*/
public class Demo1 {
    public static void main(String[] args) {
        MyRunnable mr = new MyRunnable();
        Thread th1 = new Thread(mr, "窗口一");
        Thread th2 = new Thread(mr, "窗口二");
        Thread th3 = new Thread(mr, "窗口三");
        th1.start();
        th2.start();
        th3.start();
    }
}

class MyRunnable implements Runnable {
    private static int count = 100;
    Object object = new Object();

    @Override
    public void run() {
        while (true) {
            synchronized (object) {
                if (count <= 0) {
                    break;
                } else {
                    count--;
                    System.out.println(Thread.currentThread().getName() + "   窗口在卖票,  余票:" + count);
                }
            }
        }
    }
}

